﻿Imports System.Data.SqlClient
Public Class FormCheckMorning
    Private Sub txtEmployee_Name_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmployee_Name.TextChanged
        CheckIn()
    End Sub
    Private Sub CheckIn()
        Cmd.Parameters("@Employee_Name") = "%" & txtEmployee_Name.Text & "%"
        Dim dt As New DataTable
        dt = Cmd.ExecuteDataTable("SELECT * FROM TBL_EMPLOYEE WHERE UPPER(Employee_Name) like UPPER('%'+@Employee_Name+'%')")
        If dt.Rows.Count > 0 Then
            txtEmployee_Id.Text = dt.Rows(0).Item(0)
        End If
    End Sub

    Private Sub btnCheckIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckIn.Click
        If txtEmployee_Name.Text.Trim() = "" Then
            MsgBox(My.Resources.CheckIn)
            txtEmployee_Name.Focus()
            Exit Sub
        End If
        If txtEmployee_Id.Text.Trim() = "" Then
            MsgBox("Please Input ID!")
            txtEmployee_Id.Focus()
            Exit Sub
        End If

        Cmd.Parameters("@Employee_Id") = txtEmployee_Id.Text
        Cmd.Parameters("@Check_in_Morning") = lblTimer.Text
        Cmd.Parameters("@Check_Date") = Date.Now
        Cmd.ExecuteDataTable("INSERT INTO TBL_CHECK (Employee_Id ,Check_in_Morning,Check_Date,Active)VALUES(@Employee_Id,@Check_in_Morning,@Check_Date,1)")
        FormWork.RefreshData()

        txtEmployee_Name.Text = ""
        txtEmployee_Id.Text = ""
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerCheck.Tick
        lblTimer.Text = DateAndTime.TimeString

    End Sub

    Private Sub btnCheckOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckOut.Click
        If txtEmployee_Name.Text.Trim() = "" Then
            MsgBox(My.Resources.CheckIn)
            txtEmployee_Name.Focus()
            Exit Sub
        End If
        If txtEmployee_Id.Text.Trim() = "" Then
            MsgBox("Please Input ID!")
            txtEmployee_Id.Focus()
            Exit Sub
        End If

        Try

            Cmd.Parameters("@Employee_Id") = txtEmployee_Id.Text
            Cmd.Parameters("@Check_out_Morning") = lblTimer.Text
            Cmd.Parameters("@Check_Date") = Now.ToShortDateString
            'MsgBox(Now.ToShortDateString)

            Cmd.ExecuteDataTable("UPDATE TBL_CHECK SET Check_out_Morning =@Check_out_Morning WHERE Employee_Id =@Employee_Id AND Check_Date=@Check_Date AND Active =1")


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        MsgBox("Please Check in !")
        FormWork.RefreshData()

        txtEmployee_Name.Text = ""
        txtEmployee_Id.Text = ""
    End Sub
    Private Sub btnCheck_In_Evening_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck_In_Evening.Click
        If txtEmployee_Name.Text.Trim() = "" Then
            MsgBox(My.Resources.CheckIn)
            txtEmployee_Name.Focus()
            Exit Sub
        End If
        If txtEmployee_Id.Text.Trim() = "" Then
            MsgBox("Please Input ID!")
            txtEmployee_Id.Focus()
            Exit Sub
        End If

        Try

            Cmd.Parameters("@Employee_Id") = txtEmployee_Id.Text
            Cmd.Parameters("@Check_in_Evening") = lblTimer.Text
            Cmd.Parameters("@Check_Date") = Now.ToShortDateString
            'MsgBox(Now.ToShortDateString)

            Cmd.ExecuteDataTable("UPDATE TBL_CHECK SET Check_in_Evening =@Check_in_Evening WHERE Employee_Id =@Employee_Id AND Check_Date=@Check_Date AND Active =1")


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        MsgBox("Please Check in !")
        FormWork.RefreshData()

        txtEmployee_Name.Text = ""
        txtEmployee_Id.Text = ""
    End Sub

    Private Sub btnCheck_Out_Evening_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck_Out_Evening.Click
        If txtEmployee_Name.Text.Trim() = "" Then
            MsgBox(My.Resources.CheckIn)
            txtEmployee_Name.Focus()
            Exit Sub
        End If
        If txtEmployee_Id.Text.Trim() = "" Then
            MsgBox("Please Input ID!")
            txtEmployee_Id.Focus()
            Exit Sub
        End If

        Try

            Cmd.Parameters("@Employee_Id") = txtEmployee_Id.Text
            Cmd.Parameters("@Check_out_Evening") = lblTimer.Text
            Cmd.Parameters("@Check_Date") = Now.ToShortDateString
            'MsgBox(Now.ToShortDateString)

            Cmd.ExecuteDataTable("UPDATE TBL_CHECK SET Check_out_Evening =@Check_out_Evening WHERE Employee_Id =@Employee_Id AND Check_Date=@Check_Date AND Active =1")


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        MsgBox("Please Check in !")
        FormWork.RefreshData()

        txtEmployee_Name.Text = ""
        txtEmployee_Id.Text = ""
    End Sub

    Private Sub FormCheckMorning_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
        Me.Close()
    End Sub
End Class